#include "../include/ini.h"
#ifdef COLOR32
extern unsigned long *buf_fb;
#else
extern unsigned short *buf_fb;
#endif
void _draw_bg(struct Window *w){
	int fb,file,ret;
	int i,j,k=0;
	unsigned char buf[51];
	file=open(w->bitmap,O_RDWR);
	if(file<0){
		perror("Open bgfile fauled\n");
		_exit(3);
	}
	#ifdef COLOR32
	unsigned long *buf_file;
	buf_file=mmap(buf,w->width*w->height*4,PROT_READ|PROT_WRITE,MAP_SHARED,file,0);
	#else
	unsigned short *buf_file;
	buf_file=mmap(buf,w->width*w->height*2,PROT_READ|PROT_WRITE,MAP_SHARED,file,0);
	#endif
	if(buf_file==NULL){
		perror("Map file fault\n");
		_exit(4);
	}

	for(j=w->y1;j<w->y1+w->height;j++)
	for(i=w->x1;i<w->x1+w->width;i++)
	buf_fb[j*W_480+i]=buf_file[k++];
	k=0;
	close(file);
	return;
}
void draw_back(window *w,unsigned char *path){
	w->set_bitmap_path(w,path);
	w->draw=_draw_bg;
	w->draw(w);
	return ;
}
void draw_face(void *p1,menu *p2){
	window bg;
	//-----------background------
	init(&bg);
	bg.set_type(&bg,WINDOW);
	bg.init(&bg,"lichujing",0,0,W_480,H_272);
	draw_back(&bg,"/bg.bin");
	//-----------bottom---------
	
	window bottom;
	init(&bottom);
	bottom.set_type(&bottom,BOTTOM);
	bottom.init(&bottom,"bottom",0,H_272-25,W_480,25);
	draw_back(&bottom,"/bottom.bin");
	return;
}
